﻿
using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyFirstWPF.ViewModel
{
    [Table("task")]
    public class TaskInfo
    {
        public enum TaskLevel
        {
            Normal,
            Emergency,
        }

        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }

        public string Name { get; set; }

        public string Description { get; set; }

        public string StartTime { get; set; }

        public string EndTime { get; set; }

        public int userId { get; set; }

        public int isFinished { get; set; }

        public string LastNoticeTime { get; set; }

        //public string LastDailyNoticeTime { get; set; }

        public TaskLevel Level { get; set; }

        public DateTime GetStartTime()
        {
            return DateTime.Parse(StartTime);
        }

        public void SetStartTime(DateTime time)
        {
            StartTime = time.ToString();
        } 

        // 分别用日期和时间设置时间
        public void SetStartTime(DateTime date,DateTime time)
        {
            StartTime = date.AddHours(time.Hour).AddMinutes(time.Minute).AddSeconds(time.Second).ToString();
        }

        public DateTime GetEndTime()
        {
            return DateTime.Parse(EndTime);
        }

        public void SetEndTime(DateTime time)
        {
            EndTime = time.ToString();
        }

        // 分别用日期和时间设置时间
        public void SetEndTime(DateTime date, DateTime time)
        {
            
            EndTime = date.AddHours(time.Hour).AddMinutes(time.Minute).AddSeconds(time.Second).ToString();
        }

        public DateTime GetLastNoticeTime()
        {
            return ParseTimeOrMin(LastNoticeTime);
        }

        public void SetLastNoticeTime(DateTime time)
        {
            LastNoticeTime = time.ToString();
        }

        //public DateTime GetLastDailyNoticeTime()
        //{
        //    return ParseTimeOrMin(LastDailyNoticeTime);
        //}

        //public void SetLastDailyNoticeTime(DateTime time)
        //{
        //    LastDailyNoticeTime = time.ToString();
        //}

        private DateTime ParseTimeOrMin(string timeStr)
        {
            bool ok = DateTime.TryParse(timeStr, out DateTime result);
            if (ok) return result;
            else return DateTime.MinValue;
        }

    }
}
